package code.jzh.compiler.scanner;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class DFAState {
	public int id;
	public Map<Character, Integer> edges = new HashMap<Character, Integer>();
	public boolean accepted = false;
	public boolean started = false;
	public Set<NFAState> nfaStates = new HashSet<NFAState>();
	
	public DFAState(int id, Set<NFAState> nfaStates) {
		this.id = id;
		this.nfaStates = nfaStates;
		for(NFAState nfaState : nfaStates) {
			if( nfaState.accepted==true )
				accepted = true;
		}
	}
	
	public DFAState(Set<NFAState> nfaStates) {
		this.nfaStates = nfaStates;
	}

	public void addEdge(char c, int id) {
		edges.put(c, id);
	}
	
	public boolean equal(DFAState other) {
		if(nfaStates.size()!=other.nfaStates.size())
			return false;
		for(NFAState nfaState : nfaStates) {
			if(!other.nfaStates.contains(nfaState))
				return false;
		}
		return true;
	}
	
	/*public boolean belongsTo(Set<DFAState> set) {
		if(set==null)
			return false;
		for(DFAState dfaState : set) {
			if(this.equal(dfaState))
				return true;
		}
		return false;
	}*/
	
}
